package com.cloudbroker.bcs.platform.ltb.middle.util;

import com.cloudbroker.bcs.platform.ltb.bizapi.constants.type.UpvoteType;
import com.cloudbroker.bcs.platform.ltb.common.constant.CacheKeys;
import com.cloudbroker.bcs.platform.ltb.common.util.CacheHelper;

/**
 * Created by zhaosh19213 on 2016/8/16.
 */
public class UpvoteCacheUtil {
    public static CacheHelper cacheHelper = CacheHelper.getInstance();

    //key命名规则 前缀+type+目标id用.隔开
    //评论点赞的key前缀
    public static String COMENT_UPVOTE_KEY_PREFIX = CacheKeys.UPVOTE_USER_KEY_REFIX +
            UpvoteType.COMMENT_UPVOTE.getVal()+".";
    //观点点赞的key前缀
    public static String VIEWPOINT_UPVOTE_KEY_PREFIX = CacheKeys.UPVOTE_USER_KEY_REFIX +
            UpvoteType.VIEWPOINT_UPVOTE.getVal()+".";
    //问答点赞的key前缀
    public static String ASK_UPVOTE_KEY_PREFIX = CacheKeys.UPVOTE_USER_KEY_REFIX +
            UpvoteType.ASK_UPVOTE.getVal()+".";
    //是否点赞观点
    public static boolean isUpvoteViewpoint(Long viewpoint_id, Long user_id) {
        return cacheHelper.sismember(VIEWPOINT_UPVOTE_KEY_PREFIX +viewpoint_id,
                user_id.toString());
    }

    //添加观点点赞记录
    public static void addViewpointUpvoteRecord(Long viewpoint_id, Long user_id) {
        cacheHelper.sdd(VIEWPOINT_UPVOTE_KEY_PREFIX +viewpoint_id, user_id.toString());
    }

    //删除观点点赞记录
    public static void delViewpointUpvoteRecord(Long viewpoint_id, Long user_id) {
        cacheHelper.sremove(VIEWPOINT_UPVOTE_KEY_PREFIX +viewpoint_id, user_id.toString());
    }

    //是否点赞评论
    public static boolean isUpvoteComment(Long comment_id, Long user_id) {
        return cacheHelper.sismember(COMENT_UPVOTE_KEY_PREFIX +comment_id,
                user_id.toString());
    }

    //添加评论点赞记录
    public static void addCommentUpvoteRecord(Long comment_id, Long user_id) {
        cacheHelper.sdd(COMENT_UPVOTE_KEY_PREFIX +comment_id, user_id.toString());
    }

    //删除评论点赞记录
    public static void delCommentUpvoteRecord(Long comment_id, Long user_id) {
        cacheHelper.sremove(COMENT_UPVOTE_KEY_PREFIX +comment_id, user_id.toString());
    }




    //是否点赞问答
    public static boolean isUpvoteAsk(Long ask_id, Long user_id) {
        return cacheHelper.sismember(ASK_UPVOTE_KEY_PREFIX +ask_id,
                user_id.toString());
    }
    //添加问答点赞记录
    public static void addAskUpvoteRecord(Long ask_id, Long user_id) {
        cacheHelper.sdd(ASK_UPVOTE_KEY_PREFIX +ask_id, user_id.toString());
    }

}
